﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Locomotive.MainBase.TrainList
{
    public partial class uc_Locomotive_MainBase_TrainList_TrainClass : DevExpress.XtraEditors.XtraForm
    {
        public string _LoadID, _LoadName,_LoadType = "";

        private void uc_Locomotive_MainBase_TrainList_TrainClass_FormClosing(object sender, FormClosingEventArgs e)
        {
        }

        private void tb_Name_TextChanged(object sender, EventArgs e)
        {
            if (tb_Name.Text.Trim().Length > 0)
            {
                bt_Sure.Enabled = true;
            }
            else
            {
                bt_Sure.Enabled = false;
            }
        }

        private void bt_Sure_Click(object sender, EventArgs e)
        {
            string strSQL = "";
            switch (_LoadType)
            {
                case "Add":
                    strSQL = "insert into TS_S_T_P_TrainClass(f_name,f_workerid) values('"+tb_Name.Text.Trim()+"',"+TS_Win_Locomotive_MainForm.pUserInfoMain.GuId+")";
                    break;
                case "Edit":
                    strSQL = "update TS_S_T_P_TrainClass set f_name='" + tb_Name.Text.Trim() + "',f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id="+_LoadID;
                    break;
                case "Del":
                    strSQL = "update TS_S_T_P_TrainClass set f_del=1,f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadID;
                    break;
            }
            TS_Win_Class.MySqlCom(strSQL);
            this.DialogResult = DialogResult.OK;
        }

        private void bt_Exit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void uc_Locomotive_MainBase_TrainList_TrainClass_Load(object sender, EventArgs e)
        {
            switch (_LoadType)
            {
                case "Add":
                    bt_Sure.Text = "确定增加";
                    break;
                case "Edit":
                    tb_Name.Text = _LoadName;
                    bt_Sure.Text = "确定修改";
                    break;
                case "Del":
                    tb_Name.Text = _LoadName;
                    bt_Sure.Text = "确定删除";
                    break;
            }
        }

        public uc_Locomotive_MainBase_TrainList_TrainClass()
        {
            InitializeComponent();
        }
    }
}